package educationaladministrationsystem.CSM.Mapper.Root;

import educationaladministrationsystem.Class.EssayDownload;
import educationaladministrationsystem.Class.EssayUpload;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RootMajorMapper {
    @Insert("insert into essay values (#{essayUpload.id},#{essayUpload.title},#{encodeBase64String},#{essayUpload.textInformation},#{essayUpload.date})")
    Integer saveEssay(EssayUpload essayUpload, String encodeBase64String);

    @Select("select * from essay limit #{page},#{pageNumber}")
    List<EssayDownload> downloadEssay(Integer page, Integer pageNumber);

    @Select("select max(id) from essay")
    Integer getAvailableEssayId();

    @Select("delete from essay where id=#{deleteId}")
    void deleteEssay(Integer deleteId);

    @Select("select count(*) from essay")
    double getAllPage(int pageNumber);

    @Select("select * from essay where id=#{id}")
    EssayDownload getOneDownloadEssay(Integer id);

    @Update("update essay set title=#{title},imageBase64String=#{imageBase64String},textInformation=#{textInformation} where id=#{id}")
    void updateEssay(int id, String title, String imageBase64String, String textInformation);
}
